﻿using UtilZ.Dotnet.Ex.Model;

namespace UtilZ.Dotnet.Ex.Communication.Net.Web
{
    /// <summary>
    /// Api缓存数据结果
    /// </summary>
    public class ApiBufferDataResult : ApiActionResultAbs
    {
        private string _contentType = null;
        /// <summary>
        /// http响应内容mime类型
        /// </summary>
        public string ContentType
        {
            get { return _contentType; }
            set { _contentType = value; }
        }

        private DataSource _data = null;
        /// <summary>
        /// 缓存数据
        /// </summary>
        public DataSource Data
        {
            get { return _data; }
            set { _data = value; }
        }


        /// <summary>
        /// 构造函数
        /// </summary>
        public ApiBufferDataResult()
            : base()
        {

        }


        /// <summary>
        /// 设置响应值
        /// </summary>
        /// <param name="request">http请求</param>
        /// <param name="response">http响应</param>
        protected override void PrimitiveSetResponse(HttpRequest request, HttpResponse response)
        {
            if (!string.IsNullOrWhiteSpace(this._contentType))
            {
                response.AddHeader(HttpResponseHeaders.ContentType, this._contentType);
            }

            response.Data = this._data;
        }
    }
}
